﻿@{
    ViewBag.Title = "";
    Layout = "~/Views/Shared/_Index.cshtml";
 }
<section class="content">
    <div class="row">
         <div class="col-xs-12">
              <div class="box box-info">
                   <div class="box-body">
                        <div class="table-responsive">
                             <div class="btn-group-sm" id="toolbar" role="group">
                                  <a id="btnAdd" authorize ="yes" class="btn btn-success" onclick ="showForm('')" ><i class="fa fa-plus" ></i> 新增</a>
                                  <div class="col-sm-3 pull-right">
                                       <div class="input-group input-group-sm" >
                                            <input type="text" id ="keyWord" col ="KeyWord" class="form-control" placeholder ="请输入关键字查询" />
                                            <div class="input-group-btn" >
                                                 <button type="button" class="btn btn-primary" onclick ="searchGrid()" ><i class="fa fa-search" ></i></button>
                                            </div>
                                       </div>
                                  </div>
                             </div>
                             <table id="gridTable" class="table table-hover table-striped text-nowrap">
                             </table>
                        </div>
                   </div>
              </div>
         </div>
    </div>
</section>

<script type="text/javascript">
    $(function () {
        initGrid();
    });

    function initGrid() {
        $('#gridTable').frameTable({
            url: '@Url.Action("GetPageListJson", "ChannelEntity")',
            sortName: 'CreateOn',
            sortOrder: 'Desc',
            columns: [
                 { checkbox: true, visible: true },
                 { field: 'Id', title: 'Id', visible: false },
                 { field: 'Name', title: '渠道名称', halign: "center", align: "center" },
                 { field: 'ProvinceId', title: '省', halign: "center", align: "center" },
                 { field: 'CityId', title: '市', halign: "center", align: "center" },
                 { field: 'AreaId', title: '区', halign: "center", align: "center" },
                 { field: 'Address', title: '详细地址', halign: "center", align: "center" },
                 { field: 'Remark', title: '备注说明', halign: "center", align: "center" },
                 {
                     title: '操作',
                     align: 'center',
                     formatter: function (value, row, index) {
                         var actions = [];
                         actions.push('<a href="javascript:void(0);" authorize="yes" id="btnEdit" class="btn btn-primary btn-xs" onclick="showForm(\'' + row.Id + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                         actions.push('<a href="javascript:void(0);" authorize="yes" id="btnDelete" class="btn btn-danger btn-xs" onclick="deleteData(\'' + row.Id + '\')"><i class="fa fa-trash-o"></i> 删除</a>'); 
                         return actions.join('');
                     }
                 }
            ],
            queryParams: function (params) {
                 var pagination = $('#gridTable').frameTable('getPagination', params);
                 var queryString = $('#toolbar').getWebControls(pagination);
                 return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').frameTable('search');
    }

    function showForm(id) {
        frame.openDialog({
            title: !!id ? '编辑渠道管理': '添加渠道管理', 
            content: '@Url.Content("/Sale/ChannelEntity/Form")' + '?id=' + id,
            width: '768px',
            height: '550px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function deleteData(id) {
            frame.confirm("确定要删除该数据吗？", function () {
                frame.ajax({
                    url: '@Url.Content("/Sale/ChannelEntity/DeleteData")' + '?id=' + id,
                    type: 'post',
                    success: function (obj) {
                         if (obj.success) {
                            frame.msgSuccess(obj.message);
                            searchGrid();
                        }
                        else {
                            frame.msgError(obj.message);
                        }
                    }
                });
            });
    }
</script>
